package Gtfs;


$Gtfs::VERSION = 0.01;

use strict; 
use warnings;

### OO METHODS
sub new {
	my $class = shift;

  my (%self) = @_;	

	#$self{note} = "xxx'" unless $self{note};

	#### cast the spell
  return bless(\%self, $class);
}


sub isSupported {
    my ($self, $file) = @_;
    my $domain_types = _domain_types();
    if((exists $$domain_types{$file}) &&
       ($$domain_types{$file} ne "IGNORE")) {
      return 1;
    } else {
      return 0;
    }
}

sub getClassName {
    my ($self, $file) = @_;
    my $domain_types = _domain_types();
    if(exists $$domain_types{$file}) {
      return $$domain_types{$file};
    } else {
      return "IGNORE";
    }
}

sub isFieldSupported {
    my ($self, $fieldId) = @_;
    my $field_types = _field_types();
    if((exists $$field_types{$fieldId}) &&
       ($$field_types{$fieldId} ne "IGNORE")) {
      return 1;
    } else {
      return 0;
    }
}

sub getFieldPrefix {
    my ($self, $file) = @_;
    my $domain_prefixes = _domain_prefixes();
    if(exists $$domain_prefixes{$file}) {
      return $$domain_prefixes{$file};
    } else {
      return "IGNORE";
    }
}

sub getFieldType {
    my ($self, $fieldId) = @_;
    my $field_types = _field_types();
    if(exists $$field_types{$fieldId}) {
      return $$field_types{$fieldId};
    } else {
      return "IGNORE";
    }
}

sub getDBType {
    my ($self, $fieldId) = @_;
    my $field_db_types = _field_db_types();
    if(exists $$field_db_types{$fieldId}) {
      return $$field_db_types{$fieldId};
    } 

    my $fieldType = $self->getFieldType($fieldId);
    if(exists $$field_db_types{$fieldType}) {
      return $$field_db_types{$fieldType};
    }else {
      return "IGNORE";
    }
}



my %DOMAIN_TYPES = (
"agency.txt" => "Agency",
"stops.txt" => "Stop",
"routes.txt" => "Route",
"trips.txt" => "Trip",
"stop_times.txt" => "StopTime",
"calendar.txt" => "Calendar", 
"calendar_dates.txt" => "IGNORE", #"CalendarDates", 
"shapes.txt" => "IGNORE", #"Shapes",
"frequencies.txt" => "IGNORE", #"Frequencies",
"feed_info.txt" => "IGNORE", #"FeedInfo",
"transfers.txt" => "IGNORE", #"Transfers",
"fare_rules.txt" => "IGNORE", #"FareRules",
"fare_attributes.txt" => "IGNORE", #"FareAttributes",
);

my %DOMAIN_PREFIXES = (
"IGNORE" => "IGNORE",
"agency.txt" => "agency_",
"stops.txt" => "stop_",
"routes.txt" => "route_",
"trips.txt" => "trip_",
"stop_times.txt" => "stop_time_",
"calendar.txt" => "calendar_", 
"calendar_dates.txt" => "IGNORE", #"calendar_dates", 
"shapes.txt" => "IGNORE", #"shapes",
"frequencies.txt" => "IGNORE", #"frequencies",
"feed_info.txt" => "IGNORE", #"feed_info",
"transfers.txt" => "IGNORE", #"transfers",
"fare_rules.txt" => "IGNORE", #"fare_rules",
"fare_attributes.txt" => "IGNORE", #"fare_attributes",
);

my %FIELD_TYPES = (
"feed_id" => "Long",
"agency_agency_id_field" => "Long",
"agency_agency_name_field" => "String",
"agency_agency_url_field" => "String",
"agency_agency_timezone_field" => "String",
"agency_agency_lang_field" => "String",
"agency_agency_phone_field" => "String",
"agency_agency_fare_url_field" => "String",
"stops_stop_id_field" => "Long",
"stops_stop_code_field" => "String",
"stops_stop_name_field" => "String",
"stops_stop_desc_field" => "String",
"stops_stop_lat_field" => "Double",
"stops_stop_lon_field" => "Double",
#"stops_zone_id_field" => "Long",
#"stops_stop_url_field" => "String",
"routes_route_id_field" => "Long",
"routes_agency_id_field" => "String",
"routes_route_short_name_field" => "String",
"routes_route_long_name_field" => "String",
"routes_route_desc_field" => "String",
"routes_route_type_field" => "String",
"routes_route_url_field" => "String",
"trips_route_id_field" => "String",
"trips_service_id_field" => "Long",
"trips_trip_id_field" => "Long",
"trips_trip_headsign_field" => "String",
"trips_trip_short_name_field" => "String",
"trips_direction_id_field" => "Integer",
"stop_times_trip_id_field" => "Long",
"stop_times_arrival_time_field" => "TripTimePoint",
"stop_times_departure_time_field" => "TripTimePoint",
"stop_times_stop_id_field" => "Long",
"stop_times_stop_sequence_field" => "Integer",
"stop_times_stop_headsign_field" => "String",
"stop_times_pickup_type_field" => "Integer",
"stop_times_drop_off_type_field" => "Integer",
"calendar_service_id_field" => "Long",
"calendar_monday_field" => "Boolean",
"calendar_tuesday_field" => "Boolean",
"calendar_wednesday_field" => "Boolean",
"calendar_thursday_field" => "Boolean",
"calendar_friday_field" => "Boolean",
"calendar_saturday_field" => "Boolean",
"calendar_sunday_field" => "Boolean",
"calendar_start_date_field" => "Date",
"calendar_end_date_field" => "Date"
);

my %DB_H2_TYPES = (
"String" => "TEXT",
"Byte" => "TINYINT",
"Short" => "SMALLINT",
"Integer" => "INT",
"Long" => "BIGINT",
"LongPrimaryKey" => "BIGINT", #-- IDENTITY??
"Double" => "DOUBLE",
"Float" => "REAL",
"Boolean" => "BOOLEAN",
"Date" => "Date",
"TripTimePoint" => "TripTimePoint",
"stops_stop_lat_field" => "POINT_Y",
"stops_stop_lon_field" => "POINT_X",
);

#H2 Geometry?
# (x, y, z) - (lat, lon, time) 
# Stations can be cylinders centered at lat/lon and with z0 = arrival time, z1 = departure time.

sub _domain_types { return \%DOMAIN_TYPES; }
sub _domain_prefixes { return \%DOMAIN_PREFIXES; }
sub _field_types { return \%FIELD_TYPES; }
sub _field_db_types { return \%DB_H2_TYPES; }

1;

__END__
